package com.hnucm.cooklife.model;

import com.hnucm.cooklife.base.BaseModel;
import com.hnucm.cooklife.bean.db.OrderSec;
import com.hnucm.cooklife.bean.db.Orderpic;
import com.hnucm.cooklife.bean.order.OrderData;
import com.hnucm.cooklife.contract.order.Contract;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import io.reactivex.Observable;

public class OrderModel extends BaseModel implements Contract.IOrderModel {
    @Override
    public Observable<List<OrderSec>> loadOrder() {
        return mApiServer.loadOrder()
                .map(orderData -> {
                    List<OrderSec> orderSecList = new ArrayList<>();
                    int flag = 0;

                    List<OrderData.DataDTO> dtoList = orderData.getData();
                    for (int i = 0; i < dtoList.size(); i++) {
                        if(flag != dtoList.get(i).getOgroupId()){
                            flag = dtoList.get(i).getOgroupId();
                            orderSecList.add(new OrderSec(true,dtoList.get(i).getOcato()));
                        }

                        orderSecList.add(new OrderSec(false,dtoList.get(i)));
                    }
                    return orderSecList;
                });
    }

    @Override
    public Observable<List<OrderSec>> refreshOrder() {
        return null;
    }
}
